package com.hangim.pce.common.config;

import com.hangim.pce.SystemProperties;
import com.github.pig.common.util.IdWorker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: pig
 * @description: config
 * @author: hongjiliang
 * @create: 2018-10-18 10:10
 **/

@Configuration
@EnableConfigurationProperties(SystemProperties.class)
public class Config {

    private static final Logger logger = LoggerFactory.getLogger(Config.class);

    @Autowired
    public SystemProperties systemProperties;

    @Bean
    public IdWorker idWorker() {
        long datacenterId = systemProperties.getIdWorkerDataCenterId();
        long workerId = systemProperties.getIdWorkerWorkerId();
        logger.debug("create new id worker instance. [datacenterId : {}] [workerId : {}]", datacenterId, workerId);
        return new IdWorker(workerId, datacenterId);
    }
}
